﻿unit FTPSocketSend;

interface

uses
  Windows, SysUtils, Protocol, PacketProctol, Engine, FTPProctol,
  DataPacketSend;

type

  TFtpSocketSend = Class
  private
    m_DIDataPacketSend: TIDataPacketSend;
  published
    property FDIDataPacketSend: TIDataPacketSend read m_DIDataPacketSend write m_DIDataPacketSend;

  public
    //以下由客户端发往服务器
    procedure Send_SM_FTP_HEARTBEAT;                              //(C->S) 心跳函数
    procedure Send_SM_FTP_LOGIN(sUserNuber,sUserPwd: String );  //(C->S) 用户登录
    procedure Send_SM_FTP_UPLOAD_REQUEST(sUserNuber, sUserPwd: String;
      sFileName: String; dFileSize: Int64 );     //(C->S) 文件上传请求包
    procedure Send_SM_FTP_UPLOAD_CHECK(sFilePos, sFileSize: int64;
      sFileCheck: Boolean);
    procedure Send_SM_FTP_UPLOAD_DATA(dEncryptKey:   WORD; dFileIndex: Cardinal;
      dDataBlockID:  Int64; dBlockSize: Cardinal; dCheckSum: Cardinal; pData: PByte);   //(C->S) 文件上传数据包
    procedure Send_SM_FTP_UPLOAD_OVER(sUserNuber, sUserPwd: String; sFileName: String );    //(C->S) 文件上传束
    procedure Send_SM_FTP_DOWNLOAD_FILELIST(sUserNuber, sUserPwd: AnsiString); //(C->S) 服务器文件列表
    procedure Send_SM_FTP_DOWNLOAD_FILELIST_NEXT(sUserNuber, sUserPwd: String; dFileIndex: Cardinal); //(C->S) 服务器文件列表(文件)
    procedure Send_SM_FTP_DOWNLOAD_REQUEST(sUserNuber, sUserPwd: String;
      dFileIndex: Cardinal; sFileName: String; sFileSize: int64; sCheckSum: Cardinal);     //(C->S) 文件下载请求包
    procedure Send_SM_FTP_DOWNLOAD_DATA(m_dDownFileIndex: Cardinal; m_dDownTransIndex: Int64; m_dDownEncryptKey: WORD);   //(C->S) 文件下载数据请求
    procedure Send_SM_FTP_DOWNLOAD_OVER(sUserNuber, sUserPwd: String; sFileName: String);       //(C->S) 文件下载完毕
  private
    procedure Send_CM_FTP_CUTFILE_REQUEST(m_dUpFilePos: int64; m_dUpFileIndex: Cardinal;
      m_dUpBlockSize: Cardinal; m_dUpEndBlockSize: Cardinal; m_dUpBlockCount: Int64;
      m_dUpTransIndex: Int64; m_dUpEncryptKey: WORD; m_CMD: Cardinal);
  public
    //以下由服务器发往客户端
    procedure Send_CM_GLOBAL_RESPONSIONFail(m_dPakCmd: Cardinal; m_pMsg: PChar); //(S->C) 文件上传响应
    procedure Send_CM_FTP_UPLOAD_REQUEST(m_dUpFilePos: int64; m_dUpFileIndex: Cardinal;
      m_dUpBlockSize: Cardinal; m_dUpEndBlockSize: Cardinal; m_dUpBlockCount: Int64;
      m_dUpTransIndex: Int64; m_dUpEncryptKey: WORD );  //(S->C) 允许继续上传
    procedure Send_CM_FTP_UPLOAD_CHECK(sFileSize: int64; sFileSum: Cardinal);
    procedure Send_CM_FTP_UPLOAD_DATA(m_dUpTransIndex: Int64; m_dUpEncryptKey: WORD);
    procedure Send_CM_FTP_UPLOAD_OVER;                       //(S->C) 下载结束
    procedure Send_CM_FTP_DOWNLOAD_FILELIST(m_dFileCount: Cardinal);   //(S->C) 文件下载列表
    procedure Send_CM_FTP_DOWNLOAD_FILELIST_NEXT(dFileIndex: Cardinal;  //(S->C) 文件下载列表(文件)
      dFileSize: Int64; sFileName: PChar);
    procedure Send_CM_FTP_DOWNLOAD_REQUEST(m_dDownFilePos: int64;
      m_dDownFileIndex: Cardinal; m_dDownBlockSize: Cardinal;
      m_dDownEndBlockSize: Cardinal; m_dDownBlockCount: Int64;
      m_dDownTransIndex: Int64; m_dDownEncryptKey: WORD); //(S->C) 允许继续下载
    procedure Send_CM_FTP_DOWNLOAD_DATA(dEncryptKey: WORD; dFileIndex: Cardinal;
      dDataBlockID: Int64; dBlockSize: Cardinal; dCheckSum: Cardinal; pData: PByte);   //(C->S) 文件下载数据包
    procedure Send_CM_FTP_DOWNLOAD_OVER;                 //(C->S) 文件下载结束

  public
    constructor Create(FDISocketEngine: TIEngine);
    destructor Destroy; override;
  end;

implementation

constructor TFtpSocketSend.Create(FDISocketEngine: TIEngine);
begin
  inherited Create;
  m_DIDataPacketSend := TIDataPacketSend.Create(FDISocketEngine);
end;

destructor TFtpSocketSend.Destroy;
begin
  FreeAndNil(m_DIDataPacketSend);
  inherited Destroy;
end;

procedure TFtpSocketSend.Send_SM_FTP_HEARTBEAT;
begin

end;

//(C->S) 公共方法
procedure TFtpSocketSend.Send_SM_FTP_LOGIN(sUserNuber, sUserPwd: String);
var
  m_DIGlobalPak_Head:   TDIGlobalPak_Head;                        //包头
  m_DIGlobalPak_Body:   TDIGlobalPak_Body;                        //包体
  FDIFTPPak_CSUserLogin: TDIFTPPak_CSUserLogin ;
begin
  ZeroMemory(@FDIFTPPak_CSUserLogin , SizeOf(FDIFTPPak_CSUserLogin));
  StrPCopy(FDIFTPPak_CSUserLogin.sUserNuber, sUserNuber);          //填充结构体
  StrPCopy(FDIFTPPak_CSUserLogin.sUserPwd, sUserPwd);
  with m_DIDataPacketSend do     //创建包头
  begin
    CreateDataPacketBody(m_DIGlobalPak_Head,  //包头
      m_DIGlobalPak_Body,                     //包体
      SM_LEVEL_NORMAL,                        //级别(正常)
      MD_CLIENT_TO_SERVER,                    //C->S
      BK_FTP_SIGN,                            //文件传输类别
      SM_FTP_LOGIN);                                //业务标识
    SetDPHeadLength(m_DIGlobalPak_Head, DL_GLOBALPAK_BODY_LEN +   //修改包头长度
      SizeOf(FDIFTPPak_CSUserLogin));
    WriteDataPacketToBuffer(m_DIGlobalPak_Head, m_DIGlobalPak_Body,
      @FDIFTPPak_CSUserLogin, SizeOf(FDIFTPPak_CSUserLogin));
  end;
end;

procedure TFtpSocketSend.Send_SM_FTP_UPLOAD_CHECK(sFilePos, sFileSize: int64; sFileCheck: Boolean);
var
  m_DIGlobalPak_Head: TDIGlobalPak_Head;                        //包头
  m_DIGlobalPak_Body: TDIGlobalPak_Body;                        //包体
  FDIFTPPak_FileCheck_Request: TDIFTPPak_FileCheck_Request ;
begin
  ZeroMemory(@FDIFTPPak_FileCheck_Request, SizeOf(TDIFTPPak_FileCheck_Request));
  FDIFTPPak_FileCheck_Request.dFilePos   := sFilePos;
  FDIFTPPak_FileCheck_Request.dFileSize  := sFileSize;
  FDIFTPPak_FileCheck_Request.dFileCheck := sFileCheck;
  with m_DIDataPacketSend do
  begin
    CreateDataPacketBody(m_DIGLOBALPak_Head,
      m_DIGlobalPak_Body,
      SM_LEVEL_NORMAL,
      MD_CLIENT_TO_SERVER,
      BK_FTP_SIGN,
      SM_FTP_UPLOAD_CHECK);
    SetDPHeadLength(m_DIGLOBALPak_Head, DL_GLOBALPAK_BODY_LEN +
      SizeOf(TDIFTPPak_FileCheck_Request));
    WriteDataPacketToBuffer(m_DIGLOBALPak_Head, m_DIGlobalPak_Body,
      @FDIFTPPak_FileCheck_Request, SizeOf(TDIFTPPak_FileCheck_Request));
  end;
end;

procedure TFtpSocketSend.Send_SM_FTP_UPLOAD_REQUEST(sUserNuber, sUserPwd: String;
  sFileName: String; dFileSize: Int64);
var
  m_DIGlobalPak_Head: TDIGlobalPak_Head;                        //包头
  m_DIGlobalPak_Body: TDIGlobalPak_Body;                        //包体
  FDIFTPPak_CSUpload_Request: TDIFTPPak_CSUpload_Request ;
begin
  ZeroMemory(@FDIFTPPak_CSUpload_Request, SizeOf(TDIFTPPak_CSUpload_Request));
  StrPCopy(FDIFTPPak_CSUpload_Request.pakUserInfo.sUserNuber, sUserNuber);          //填充结构体
  StrPCopy(FDIFTPPak_CSUpload_Request.pakUserInfo.sUserPwd, sUserPwd);
  StrPCopy(FDIFTPPak_CSUpload_Request.sFileName, sFileName);
  FDIFTPPak_CSUpload_Request.dFileSize := dFileSize;
  with m_DIDataPacketSend do     //创建包头
  begin
    CreateDataPacketBody(m_DIGlobalPak_Head,  //包头
      m_DIGlobalPak_Body,                     //包体
      SM_LEVEL_NORMAL,                        //级别(正常)
      MD_CLIENT_TO_SERVER,                    //C->S
      BK_FTP_SIGN,                            //文件传输类别
      SM_FTP_UPLOAD_REQUEST);                //业务标识
    SetDPHeadLength(m_DIGlobalPak_Head, DL_GLOBALPAK_BODY_LEN +   //修改包头长度
      SizeOf(TDIFTPPak_CSUpload_Request));
    WriteDataPacketToBuffer(m_DIGlobalPak_Head, m_DIGlobalPak_Body,
      @FDIFTPPak_CSUpload_Request, SizeOf(TDIFTPPak_CSUpload_Request));
  end;
end;

procedure TFtpSocketSend.Send_SM_FTP_UPLOAD_DATA(dEncryptKey: WORD;
  dFileIndex: Cardinal; dDataBlockID: Int64; dBlockSize: Cardinal;
  dCheckSum: Cardinal; pData: PByte);
var
  m_DIGlobalPak_Head: TDIGlobalPak_Head;                        //包头
  m_DIGlobalPak_Body: TDIGlobalPak_Body;                        //包体
  DIFTPPak_TransData_Response: TDIFTPPak_TransData_Response;
begin
  ZeroMemory(@DIFTPPak_TransData_Response, SizeOf(TDIFTPPak_TransData_Response));
  DIFTPPak_TransData_Response.dEncryptKey := dEncryptKey;
  DIFTPPak_TransData_Response.dFileIndex := dFileIndex;
  DIFTPPak_TransData_Response.dDataBlockID := dDataBlockID;
  DIFTPPak_TransData_Response.dBlockSize := dBlockSize;
  DIFTPPak_TransData_Response.dCheckSum := dCheckSum;
  with m_DIDataPacketSend do     //创建包头
  begin
    CreateDataPacketBody(m_DIGlobalPak_Head,  //包头
      m_DIGlobalPak_Body,                     //包体
      SM_LEVEL_NORMAL,                        //级别(正常)
      MD_CLIENT_TO_SERVER,                    //C->S
      BK_FTP_SIGN,                            //文件传输类别
      SM_FTP_UPLOAD_DATA);                   //业务标识
    SetDPHeadLength(m_DIGlobalPak_Head, DL_GLOBALPAK_BODY_LEN +   //修改包头长度
      SizeOf(TDIFTPPak_TransData_Response) +
      DIFTPPak_TransData_Response.dBlockSize);
    WriteDataPacketToBuffer(m_DIGlobalPak_Head, m_DIGlobalPak_Body,
      @DIFTPPak_TransData_Response, SizeOf(TDIFTPPak_TransData_Response),
      pData, DIFTPPak_TransData_Response.dBlockSize);
  end;
end;

procedure TFtpSocketSend.Send_SM_FTP_UPLOAD_OVER(sUserNuber, sUserPwd: string;
  sFileName: string );   //(C->S) 文件上传束
var
  m_DIGlobalPak_Head: TDIGlobalPak_Head;                        //包头
  m_DIGlobalPak_Body: TDIGlobalPak_Body;                        //包体
  FDIFTPPak_CSUpload_OVER: TDIFTPPak_CSUpload_OVER;
begin
  ZeroMemory(@FDIFTPPak_CSUpload_OVER, SizeOf(TDIFTPPak_CSUpload_OVER));
  StrPCopy(FDIFTPPak_CSUpload_OVER.pakUserInfo.sUserNuber, sUserNuber);          //填充结构体
  StrPCopy(FDIFTPPak_CSUpload_OVER.pakUserInfo.sUserPwd, sUserPwd);
  StrPCopy(FDIFTPPak_CSUpload_OVER.sFileName, sFileName);
  with m_DIDataPacketSend do       //创建包头
  begin
    CreateDataPacketBody(m_DIGlobalPak_Head,  //包头
      m_DIGlobalPak_Body,                     //包体
      SM_LEVEL_NORMAL,                        //级别(正常)
      MD_CLIENT_TO_SERVER,                    //C->S
      BK_FTP_SIGN,                            //文件传输类别
      SM_FTP_UPLOAD_OVER );                   //业务标识
    SetDPHeadLength(m_DIGlobalPak_Head, DL_GLOBALPAK_BODY_LEN +   //修改包头长度
      SizeOf(TDIFTPPak_CSUpload_OVER));
    WriteDataPacketToBuffer(m_DIGlobalPak_Head, m_DIGlobalPak_Body,
      @FDIFTPPak_CSUpload_OVER, SizeOf(TDIFTPPak_CSUpload_OVER) );
  end;
end;

procedure TFtpSocketSend.Send_SM_FTP_DOWNLOAD_FILELIST(sUserNuber, sUserPwd: AnsiString);
var
  m_DIGlobalPak_Head:   TDIGlobalPak_Head;                        //包头
  m_DIGlobalPak_Body:   TDIGlobalPak_Body;                        //包体
  FDIFTPPak_CSUserLogin: TDIFTPPak_CSUserLogin;
  size: AnsiString;
begin
  ZeroMemory(@FDIFTPPak_CSUserLogin , SizeOf(FDIFTPPak_CSUserLogin));
  StrPCopy(FDIFTPPak_CSUserLogin.sUserNuber, sUserNuber);          //填充结构体
  StrPCopy(FDIFTPPak_CSUserLogin.sUserPwd, sUserPwd);
  with m_DIDataPacketSend do   //创建包头
  begin
    CreateDataPacketBody(m_DIGlobalPak_Head,  //包头
      m_DIGlobalPak_Body,                     //包体
      SM_LEVEL_NORMAL,                        //级别(正常)
      MD_CLIENT_TO_SERVER,                    //C->S
      BK_FTP_SIGN,                            //文件传输类别
      SM_FTP_DOWNLOAD_FILELIST);             //业务标识
    SetDPHeadLength(m_DIGlobalPak_Head, DL_GLOBALPAK_BODY_LEN +   //修改包头长度
      SizeOf(TDIFTPPak_CSUserLogin));
    WriteDataPacketToBuffer(m_DIGlobalPak_Head, m_DIGlobalPak_Body,
      @FDIFTPPak_CSUserLogin, SizeOf(TDIFTPPak_CSUserLogin));
  end;
end;

procedure TFtpSocketSend.Send_SM_FTP_DOWNLOAD_FILELIST_NEXT(sUserNuber, sUserPwd: String;
  dFileIndex: Cardinal);
var
  m_DIGlobalPak_Head:   TDIGlobalPak_Head;                        //包头
  m_DIGlobalPak_Body:   TDIGlobalPak_Body;                        //包体
  DIFTPPak_SCFileList_Next: TDIFTPPak_SCFileList_Next ;
begin
  ZeroMemory(@DIFTPPak_SCFileList_Next , SizeOf(TDIFTPPak_SCFileList_Next));
  StrPCopy(DIFTPPak_SCFileList_Next.pakUserInfo.sUserNuber, sUserNuber);
  StrPCopy(DIFTPPak_SCFileList_Next.pakUserInfo.sUserPwd, sUserPwd);
  DIFTPPak_SCFileList_Next.dFileIndex := dFileIndex;
  with m_DIDataPacketSend do   //创建包头
  begin
    CreateDataPacketBody(m_DIGlobalPak_Head,  //包头
      m_DIGlobalPak_Body,                     //包体
      SM_LEVEL_NORMAL,                        //级别(正常)
      MD_CLIENT_TO_SERVER,                    //C->S
      BK_FTP_SIGN,                            //文件传输类别
      SM_FTP_DOWNLOAD_FILELIST_NEXT );        //业务标识
    SetDPHeadLength(m_DIGlobalPak_Head, DL_GLOBALPAK_BODY_LEN +   //修改包头长度
      SizeOf(TDIFTPPak_SCFileList_Next));
    WriteDataPacketToBuffer(m_DIGlobalPak_Head, m_DIGlobalPak_Body,
      @DIFTPPak_SCFileList_Next, SizeOf(TDIFTPPak_SCFileList_Next));
  end;
end;

procedure TFtpSocketSend.Send_SM_FTP_DOWNLOAD_REQUEST(sUserNuber, sUserPwd: String;
  dFileIndex: Cardinal; sFileName: String; sFileSize: int64; sCheckSum: Cardinal);
var
  m_DIGlobalPak_Head:   TDIGlobalPak_Head;                        //包头
  m_DIGlobalPak_Body:   TDIGlobalPak_Body;                        //包体
  DIFTPPak_CSDownload_Request: TDIFTPPak_CSDownload_Request ;
begin
  ZeroMemory(@DIFTPPak_CSDownload_Request , SizeOf(TDIFTPPak_CSDownload_Request));
  StrPCopy(DIFTPPak_CSDownload_Request.pakUserInfo.sUserNuber, sUserNuber);
  StrPCopy(DIFTPPak_CSDownload_Request.pakUserInfo.sUserPwd, sUserPwd);
  StrPCopy(DIFTPPak_CSDownload_Request.sFileName, sFileName);
  DIFTPPak_CSDownload_Request.dFileIndex := dFileIndex;
  DIFTPPak_CSDownload_Request.dFileSize  := sFileSize;
  DIFTPPak_CSDownload_Request.dCheckSum  := sCheckSum;
  with m_DIDataPacketSend do   //创建包头
  begin
    CreateDataPacketBody(m_DIGlobalPak_Head,  //包头
      m_DIGlobalPak_Body,                     //包体
      SM_LEVEL_NORMAL,                        //级别(正常)
      MD_CLIENT_TO_SERVER,                    //C->S
      BK_FTP_SIGN,                            //文件传输类别
      SM_FTP_DOWNLOAD_REQUEST);               //业务标识
    SetDPHeadLength(m_DIGlobalPak_Head, DL_GLOBALPAK_BODY_LEN +   //修改包头长度
      SizeOf(TDIFTPPak_CSDownload_Request));
    WriteDataPacketToBuffer(m_DIGlobalPak_Head, m_DIGlobalPak_Body,
      @DIFTPPak_CSDownload_Request, SizeOf(TDIFTPPak_CSDownload_Request));
  end;
end;

procedure TFtpSocketSend.Send_SM_FTP_DOWNLOAD_DATA(m_dDownFileIndex: Cardinal;
  m_dDownTransIndex: Int64; m_dDownEncryptKey: WORD);
var
  m_DIGlobalPak_Head:   TDIGlobalPak_Head;                        //包头
  m_DIGlobalPak_Body:   TDIGlobalPak_Body;                        //包体
  DIFTPPak_TransData_Request: TDIFTPPak_TransData_Request;
begin
  ZeroMemory(@DIFTPPak_TransData_Request , SizeOf(TDIFTPPak_TransData_Request));
  DIFTPPak_TransData_Request.dFileIndex := m_dDownFileIndex;
  DIFTPPak_TransData_Request.dDataBlockID := m_dDownTransIndex;
  DIFTPPak_TransData_Request.dEncryptKey := m_dDownEncryptKey;
  with m_DIDataPacketSend do //创建包头
  begin
    CreateDataPacketBody(m_DIGlobalPak_Head,  //包头
      m_DIGlobalPak_Body,                     //包体
      SM_LEVEL_NORMAL,                        //级别(正常)
      MD_CLIENT_TO_SERVER,                    //C->S
      BK_FTP_SIGN,                            //文件传输类别
      SM_FTP_DOWNLOAD_DATA );                 //业务标识
    SetDPHeadLength(m_DIGlobalPak_Head, DL_GLOBALPAK_BODY_LEN +   //修改包头长度
      SizeOf(TDIFTPPak_TransData_Request));
    WriteDataPacketToBuffer(m_DIGlobalPak_Head, m_DIGlobalPak_Body,
      @DIFTPPak_TransData_Request, SizeOf(TDIFTPPak_TransData_Request));
  end;
end;

procedure TFtpSocketSend.Send_SM_FTP_DOWNLOAD_OVER(sUserNuber, sUserPwd:  String;
  sFileName: String);
var
  m_DIGlobalPak_Head:   TDIGlobalPak_Head;                        //包头
  m_DIGlobalPak_Body:   TDIGlobalPak_Body;                        //包体
  DIFTPPak_CSDownload_OVER: TDIFTPPak_CSDownload_OVER;
begin
  ZeroMemory(@DIFTPPak_CSDownload_OVER , SizeOf(TDIFTPPak_CSDownload_OVER));
  StrPCopy(DIFTPPak_CSDownload_OVER.pakUserInfo.sUserNuber, sUserNuber);
  StrPCopy(DIFTPPak_CSDownload_OVER.pakUserInfo.sUserPwd, sUserPwd);
  StrPCopy(DIFTPPak_CSDownload_OVER.sFileName, sFileName);
  with m_DIDataPacketSend do    //创建包头
  begin
    CreateDataPacketBody(m_DIGlobalPak_Head,  //包头
      m_DIGlobalPak_Body,                     //包体
      SM_LEVEL_NORMAL,                        //级别(正常)
      MD_CLIENT_TO_SERVER,                    //C->S
      BK_FTP_SIGN,                            //文件传输类别
      SM_FTP_DOWNLOAD_OVER );                 //业务标识
    SetDPHeadLength(m_DIGlobalPak_Head, DL_GLOBALPAK_BODY_LEN +   //修改包头长度
      SizeOf(TDIFTPPak_CSDownload_OVER));
    WriteDataPacketToBuffer(m_DIGlobalPak_Head, m_DIGlobalPak_Body,
      @DIFTPPak_CSDownload_OVER, SizeOf(TDIFTPPak_CSDownload_OVER));
  end;
end;

//以下服务器发往客户端
procedure TFtpSocketSend.Send_CM_GLOBAL_RESPONSIONFail(m_dPakCmd: Cardinal; m_pMsg: PChar);
var
  m_DIGlobalPak_Head:   TDIGlobalPak_Head;                      //包头
  m_DIGlobalPak_Body:   TDIGlobalPak_Body;                      //包体
  DIGlobalPak_Responsion:     TDIGlobalPak_Responsion;          //公共返回包
begin
  DIGlobalPak_Responsion.bState := 0;
  DIGlobalPak_Responsion.dMsgLen := StrLen(m_pMsg);
  with m_DIDataPacketSend do  //创建包头
  begin
    CreateDataPacketBody(m_DIGlobalPak_Head,  //包头
      m_DIGlobalPak_Body,                     //包体
      SM_LEVEL_NORMAL,                        //级别(正常)
      MD_SERVER_TO_CLIENT,                    //S->C
      BK_FTP_SIGN,                            //文件传输类别
      m_dPakCmd);                            //业务标识(失败)
    SetDPHeadLength( m_DIGlobalPak_Head, DL_GLOBALPAK_BODY_LEN +            //修改包头长度
      DL_GLOBALPAK_RESPONSION_LEN + DIGlobalPak_Responsion.dMsgLen ); //公共包+字串
    WriteDataPacketToBuffer(m_DIGlobalPak_Head, m_DIGlobalPak_Body,
      @DIGlobalPak_Responsion, DL_GLOBALPAK_RESPONSION_LEN,
      @m_pMsg, DIGlobalPak_Responsion.dMsgLen);
  end;
end;

procedure TFtpSocketSend.Send_CM_FTP_CUTFILE_REQUEST(m_dUpFilePos: int64;
  m_dUpFileIndex: Cardinal; m_dUpBlockSize: Cardinal; m_dUpEndBlockSize: Cardinal;
  m_dUpBlockCount: Int64; m_dUpTransIndex: Int64; m_dUpEncryptKey: WORD; m_CMD: Cardinal);
var
  m_DIGlobalPak_Head: TDIGlobalPak_Head;                      //包头
  m_DIGlobalPak_Body: TDIGlobalPak_Body;                      //包体
  DIGlobalPak_Responsion: TDIGlobalPak_Responsion;          //公共返回包
  DIFTPPak_CutFile_Response: TDIFTPPak_CutFile_Response;       //业务包
begin
  DIGlobalPak_Responsion.bState := 1;
  DIGlobalPak_Responsion.dMsgLen := 0;
  ZeroMemory(@DIFTPPak_CutFile_Response, SizeOf(TDIFTPPak_CutFile_Response));
  DIFTPPak_CutFile_Response.dFilePos := m_dUpFilePos;
  DIFTPPak_CutFile_Response.dFileIndex := m_dUpFileIndex;
  DIFTPPak_CutFile_Response.dBlockSize := m_dUpBlockSize;
  DIFTPPak_CutFile_Response.dEndBlockSize := m_dUpEndBlockSize;
  DIFTPPak_CutFile_Response.dBlockCount := m_dUpBlockCount;
  DIFTPPak_CutFile_Response.dDataBlockID := m_dUpTransIndex;
  DIFTPPak_CutFile_Response.dEncryptKey := m_dUpEncryptKey;
  with m_DIDataPacketSend do   //创建包头
  begin
    CreateDataPacketBody(m_DIGlobalPak_Head,  //包头
      m_DIGlobalPak_Body,                     //包体
      SM_LEVEL_NORMAL,                        //级别(正常)
      MD_SERVER_TO_CLIENT,                    //S->C
      BK_FTP_SIGN,                            //文件传输类别
      m_CMD);                                //业务标识
    SetDPHeadLength(m_DIGlobalPak_Head, DL_GLOBALPAK_BODY_LEN +   //修改包头长度
      DL_GLOBALPAK_RESPONSION_LEN+ SizeOf(TDIFTPPak_CutFile_Response));
    WriteDataPacketToBuffer(m_DIGlobalPak_Head, m_DIGlobalPak_Body,
      @DIGlobalPak_Responsion, DL_GLOBALPAK_RESPONSION_LEN,
      @DIFTPPak_CutFile_Response, SizeOf(TDIFTPPak_CutFile_Response));
  end;
end;


procedure TFtpSocketSend.Send_CM_FTP_UPLOAD_REQUEST(m_dUpFilePos: int64;
  m_dUpFileIndex: Cardinal; m_dUpBlockSize: Cardinal; m_dUpEndBlockSize: Cardinal;
  m_dUpBlockCount: Int64; m_dUpTransIndex: Int64; m_dUpEncryptKey: WORD);
begin
  Send_CM_FTP_CUTFILE_REQUEST(m_dUpFilePos, m_dUpFileIndex, m_dUpBlockSize, m_dUpEndBlockSize,
    m_dUpBlockCount, m_dUpTransIndex, m_dUpEncryptKey, CM_FTP_UPLOAD_REQUEST);
end;

procedure TFtpSocketSend.Send_CM_FTP_UPLOAD_CHECK(sFileSize: int64;
  sFileSum: Cardinal);
var
  m_DIGlobalPak_Head:   TDIGlobalPak_Head;                      //包头
  m_DIGlobalPak_Body:   TDIGlobalPak_Body;                      //包体
  DIGlobalPak_Responsion:     TDIGlobalPak_Responsion;          //公共返回包
  DIFTPPak_FileCheck_Response: TDIFTPPak_FileCheck_Response; //服务器发送包
begin
  DIGlobalPak_Responsion.bState := 1;
  DIGlobalPak_Responsion.dMsgLen := 0;
  ZeroMemory(@DIFTPPak_FileCheck_Response, SizeOf(TDIFTPPak_FileCheck_Response));
  DIFTPPak_FileCheck_Response.dFileSize := sFileSize;
  DIFTPPak_FileCheck_Response.dCheckSum := sFileSum;
  with m_DIDataPacketSend do
  begin
    CreateDataPacketBody(m_DIGlobalPak_Head,
      m_DIGlobalPak_Body,
      SM_LEVEL_NORMAL,                        //级别(正常)
      MD_SERVER_TO_CLIENT,                    //S->C
      BK_FTP_SIGN,                            //文件传输类别
      CM_FTP_UPLOAD_CHECK);                   //业务标识
    SetDPHeadLength(m_DIGlobalPak_Head, DL_GLOBALPAK_BODY_LEN +   //修改包头长度
      DL_GLOBALPAK_RESPONSION_LEN + SizeOf(TDIFTPPak_FileCheck_Response));
    WriteDataPacketToBuffer(m_DIGlobalPak_Head, m_DIGlobalPak_Body,
      @DIGlobalPak_Responsion, DL_GLOBALPAK_RESPONSION_LEN,
      @DIFTPPak_FileCheck_Response, SizeOf(TDIFTPPak_FileCheck_Response));
  end;
end;

procedure TFtpSocketSend.Send_CM_FTP_UPLOAD_DATA(m_dUpTransIndex: Int64; m_dUpEncryptKey: WORD);
var
  m_DIGlobalPak_Head:   TDIGlobalPak_Head;                      //包头
  m_DIGlobalPak_Body:   TDIGlobalPak_Body;                      //包体
  DIGlobalPak_Responsion: TDIGlobalPak_Responsion;          //公共返回包
  DIFTPPak_TransData_Request: TDIFTPPak_TransData_Request;      //打包
begin
  DIGlobalPak_Responsion.bState := 1;
  DIGlobalPak_Responsion.dMsgLen := 0;
  ZeroMemory(@DIFTPPak_TransData_Request, SizeOf(TDIFTPPak_TransData_Request));
  DIFTPPak_TransData_Request.dDataBlockID := m_dUpTransIndex;
  DIFTPPak_TransData_Request.dEncryptKey := m_dUpEncryptKey;
  with m_DIDataPacketSend do     //创建包头
  begin
    CreateDataPacketBody(m_DIGlobalPak_Head,  //包头
      m_DIGlobalPak_Body,                     //包体
      SM_LEVEL_NORMAL,                        //级别(正常)
      MD_SERVER_TO_CLIENT,                    //S->C
      BK_FTP_SIGN,                            //文件传输类别
      CM_FTP_UPLOAD_DATA);                   //业务标识
    SetDPHeadLength(m_DIGlobalPak_Head, DL_GLOBALPAK_BODY_LEN +   //修改包头长度
      DL_GLOBALPAK_RESPONSION_LEN + SizeOf(TDIFTPPak_TransData_Request));
    WriteDataPacketToBuffer(m_DIGlobalPak_Head, m_DIGlobalPak_Body,
      @DIGlobalPak_Responsion, DL_GLOBALPAK_RESPONSION_LEN,
      @DIFTPPak_TransData_Request, SizeOf(TDIFTPPak_TransData_Request));
  end;
end;

procedure TFtpSocketSend.Send_CM_FTP_UPLOAD_OVER;
var
  m_DIGlobalPak_Head:   TDIGlobalPak_Head;                          //包头
  m_DIGlobalPak_Body:   TDIGlobalPak_Body;                          //包体
  DIGlobalPak_Responsion: TDIGlobalPak_Responsion;          //公共返回包
begin
  DIGlobalPak_Responsion.bState := 1;
  DIGlobalPak_Responsion.dMsgLen := 0;
  with m_DIDataPacketSend do   //创建包头
  begin
    CreateDataPacketBody(m_DIGlobalPak_Head,  //包头
      m_DIGlobalPak_Body,                     //包体
      SM_LEVEL_NORMAL,                        //级别(正常)
      MD_SERVER_TO_CLIENT,                    //S->C
      BK_FTP_SIGN,                            //文件传输类别
      CM_FTP_UPLOAD_OVER );                   //业务标识
    SetDPHeadLength(m_DIGlobalPak_Head, DL_GLOBALPAK_BODY_LEN +   //修改包头长度
      DL_GLOBALPAK_RESPONSION_LEN);
    WriteDataPacketToBuffer(m_DIGlobalPak_Head, m_DIGlobalPak_Body,
      @DIGlobalPak_Responsion, DL_GLOBALPAK_RESPONSION_LEN);
  end;
end;

procedure TFtpSocketSend.Send_CM_FTP_DOWNLOAD_FILELIST(m_dFileCount: Cardinal);   //(S->C) 文件下载列表
                                        
var
  m_DIGlobalPak_Head:   TDIGlobalPak_Head;                          //包头
  m_DIGlobalPak_Body:   TDIGlobalPak_Body;                          //包体
  DIGlobalPak_Responsion:         TDIGlobalPak_Responsion;          //公共返回包
  DIFTPPak_SCFileList_Response:   TDIFTPPak_SCFileList_Response;
begin
  DIGlobalPak_Responsion.bState := 1;
  DIGlobalPak_Responsion.dMsgLen := 0;
  DIFTPPak_SCFileList_Response.dFileCount := m_dFileCount;
  with m_DIDataPacketSend do          //创建包头
  begin
    CreateDataPacketBody(m_DIGlobalPak_Head,  //包头
      m_DIGlobalPak_Body,                     //包体
      SM_LEVEL_NORMAL,                        //级别(正常)
      MD_SERVER_TO_CLIENT,                    //S->C
      BK_FTP_SIGN,                            //文件传输类别
      CM_FTP_DOWNLOAD_FILELIST);             //业务标识
    SetDPHeadLength(m_DIGlobalPak_Head, DL_GLOBALPAK_BODY_LEN +   //修改包头长度
      DL_GLOBALPAK_RESPONSION_LEN + SizeOf(TDIFTPPak_SCFileList_Response));
    WriteDataPacketToBuffer(m_DIGlobalPak_Head, m_DIGlobalPak_Body,
      @DIGlobalPak_Responsion, DL_GLOBALPAK_RESPONSION_LEN,
      @DIFTPPak_SCFileList_Response, SizeOf(TDIFTPPak_SCFileList_Response));
  end;
end;

procedure TFtpSocketSend.Send_CM_FTP_DOWNLOAD_FILELIST_NEXT(dFileIndex: Cardinal;
  dFileSize: Int64; sFileName: PChar);
var
  m_DIGlobalPak_Head:   TDIGlobalPak_Head;                          //包头
  m_DIGlobalPak_Body:   TDIGlobalPak_Body;                          //包体
  DIGlobalPak_Responsion:         TDIGlobalPak_Responsion;          //公共返回包
  DIFTPPak_SCFileListNext_Response: TDIFTPPak_SCFileListNext_Response;
begin
  DIGlobalPak_Responsion.bState := 1;
  DIGlobalPak_Responsion.dMsgLen := 0;
  DIFTPPak_SCFileListNext_Response.dFileIndex := dFileIndex;
  DIFTPPak_SCFileListNext_Response.dFileSize := dFileSize;
  StrCopy(DIFTPPak_SCFileListNext_Response.sFileName, sFileName);
  with m_DIDataPacketSend do //创建包头
  begin
    CreateDataPacketBody(m_DIGlobalPak_Head,  //包头
      m_DIGlobalPak_Body,                     //包体
      SM_LEVEL_NORMAL,                        //级别(正常)
      MD_SERVER_TO_CLIENT,                    //S->C
      BK_FTP_SIGN,                            //文件传输类别
      CM_FTP_DOWNLOAD_FILELIST_NEXT );        //业务标识
    SetDPHeadLength(m_DIGlobalPak_Head, DL_GLOBALPAK_BODY_LEN +   //修改包头长度
      DL_GLOBALPAK_RESPONSION_LEN + SizeOf(TDIFTPPak_SCFileListNext_Response));
    WriteDataPacketToBuffer(m_DIGlobalPak_Head, m_DIGlobalPak_Body,
      @DIGlobalPak_Responsion, DL_GLOBALPAK_RESPONSION_LEN,
      @DIFTPPak_SCFileListNext_Response, SizeOf(TDIFTPPak_SCFileListNext_Response));
  end;
end;

procedure TFtpSocketSend.Send_CM_FTP_DOWNLOAD_REQUEST(m_dDownFilePos: int64;
  m_dDownFileIndex: Cardinal; m_dDownBlockSize: Cardinal; m_dDownEndBlockSize: Cardinal;
  m_dDownBlockCount: Int64; m_dDownTransIndex: Int64; m_dDownEncryptKey: WORD);
begin
  Send_CM_FTP_CUTFILE_REQUEST(m_dDownFilePos, m_dDownFileIndex, m_dDownBlockSize, m_dDownEndBlockSize,
    m_dDownBlockCount, m_dDownTransIndex, m_dDownEncryptKey, CM_FTP_DOWNLOAD_REQUEST);
end;

procedure TFtpSocketSend.Send_CM_FTP_DOWNLOAD_DATA(dEncryptKey: WORD; dFileIndex: Cardinal;
  dDataBlockID: Int64; dBlockSize: Cardinal; dCheckSum: Cardinal; pData: PByte);
var
  m_DIGlobalPak_Head:   TDIGlobalPak_Head;                        //包头
  m_DIGlobalPak_Body:   TDIGlobalPak_Body;                        //包体
  DIFTPPak_CSDownload_DataResponsion: TDIFTPPak_CSDownload_DataResponsion;
begin
  ZeroMemory(@DIFTPPak_CSDownload_DataResponsion, SizeOf(TDIFTPPak_CSDownload_DataResponsion));
  with DIFTPPak_CSDownload_DataResponsion do
  begin
    pakGlobalRes .bState := 1;
    pakGlobalRes.dMsgLen := 0;
    pakTransRes.dEncryptKey := dEncryptKey;
    pakTransRes.dFileIndex := dFileIndex;
    pakTransRes.dDataBlockID := dDataBlockID;
    pakTransRes.dBlockSize := dBlockSize;
    pakTransRes.dCheckSum := dCheckSum;
  end;
  with m_DIDataPacketSend do   //创建包头
  begin
    CreateDataPacketBody(m_DIGlobalPak_Head,  //包头
      m_DIGlobalPak_Body,                     //包体
      SM_LEVEL_NORMAL,                        //级别(正常)
      MD_CLIENT_TO_SERVER,                    //C->S
      BK_FTP_SIGN,                            //文件传输类别
      CM_FTP_DOWNLOAD_DATA);                //业务标识
    SetDPHeadLength(m_DIGlobalPak_Head, DL_GLOBALPAK_BODY_LEN +   //修改包头长度
      SizeOf(TDIFTPPak_CSDownload_DataResponsion) +
      DIFTPPak_CSDownload_DataResponsion.pakTransRes.dBlockSize );
    WriteDataPacketToBuffer(m_DIGlobalPak_Head, m_DIGlobalPak_Body,
      @DIFTPPak_CSDownload_DataResponsion,
      SizeOf(TDIFTPPak_CSDownload_DataResponsion),
      pData, DIFTPPak_CSDownload_DataResponsion.pakTransRes.dBlockSize);
  end;
end;

procedure TFtpSocketSend.Send_CM_FTP_DOWNLOAD_OVER;        //(C->S) 文件下载结束
var
  m_DIGlobalPak_Head:   TDIGlobalPak_Head;                          //包头
  m_DIGlobalPak_Body:   TDIGlobalPak_Body;                          //包体
  DIGlobalPak_Responsion: TDIGlobalPak_Responsion;                  //公共返回包
begin
  DIGlobalPak_Responsion.bState := 1;
  DIGlobalPak_Responsion.dMsgLen := 0;

  with m_DIDataPacketSend do   //创建包头
  begin
    CreateDataPacketBody(m_DIGlobalPak_Head,  //包头
      m_DIGlobalPak_Body,                     //包体
      SM_LEVEL_NORMAL,                        //级别(正常)
      MD_SERVER_TO_CLIENT,                    //S->C
      BK_FTP_SIGN,                            //文件传输类别
      CM_FTP_DOWNLOAD_OVER);                 //业务标识
    SetDPHeadLength(m_DIGlobalPak_Head, DL_GLOBALPAK_BODY_LEN +   //修改包头长度
      DL_GLOBALPAK_RESPONSION_LEN );
    WriteDataPacketToBuffer(m_DIGlobalPak_Head, m_DIGlobalPak_Body,
      @DIGlobalPak_Responsion, DL_GLOBALPAK_RESPONSION_LEN);
  end;
end;


end.
